/*
edcblist.js  1.0
tfComboListBox javascript functions
*/

var ERROR_DISPLAY_TIMEOUT=1000;
var ERROR_DISPLAY_COLOR="red";
var ERROR_DISPLAY_FONT_WEIGHT="bold";
function getItemLabel(rootElem){
if(rootElem.tagName.toLowerCase()=='label'){
return rootElem;
}else{
for(var i=0;i<rootElem.childNodes.length;i++){
var childElement=rootElem.childNodes[i];
var childReturn=getItemLabel(childElement);
if(childReturn!=null){
return childReturn;
}
}
return null;
}
}
function ClickedCheckBox(labelElement,item){
this.labelElement=labelElement;
this.item=item;
}
function DropDownButton(imageDivId,imageUpSrc,imageDownSrc,imageOverSrc,imageSize){
this.imageDiv=xGetElementById(imageDivId);
this.imageUpSrc=imageUpSrc;
this.imageDownSrc=imageDownSrc;
this.imageOverSrc=imageOverSrc;
this.imageSize=imageSize;
this.image=document.createElement('img');
this.image.width=imageSize;
this.image.height=imageSize;
this.image.src=imageUpSrc;
this.imageDiv.appendChild(this.image);
}
DropDownButton.prototype.showMouseUp=function(){
this.image.src=this.imageUpSrc;
}
DropDownButton.prototype.showMouseDown=function(){
this.image.src=this.imageDownSrc;
}
DropDownButton.prototype.showMouseOver=function(){
this.image.src=this.imageOverSrc;
}
function tfCBList(name,maxSelectionSize,selectionTextUpdateFunction,checkBoxList,dropDownButton){
this.name=name;
this.maxSelectionSize=maxSelectionSize;
this.selectionTextFormatter=selectionTextUpdateFunction;
this.checkBoxList=checkBoxList;
this.clickedCheckBoxes=[];
this.mainDiv=xGetElementById(name+":Div");
this.comboBoxDiv=xGetElementById(name+"_combobox");
this.comboTextDiv=xGetElementById(name+"_comboboxtext");
this.checkBoxListDiv=xGetElementById(name+"_checkboxlist");
this.iFrameHackID=name+"_iframehack";
this.dropDownButton=dropDownButton;
this.mouseOverHandler=function(CallerObject){
return function(){
CallerObject.dropDownButton.showMouseOver();
CallerObject.comboBoxDiv.className="comboBoxFocus";
}
}(this);
this.mouseOutHandler=function(CallerObject){
return function(){
CallerObject.dropDownButton.showMouseUp();
CallerObject.comboBoxDiv.className="comboBox";
}
}(this);
this.mouseDownHandler=function(CallerObject){
return function(){
CallerObject.dropDownButton.showMouseDown();
}
}(this);
this.mouseUpHandler=function(CallerObject){
return function(){
dropDownBtn.showOver();
if(is.ie)
{
window.event.cancelBubble=true;
}else{
e.stopPropagation();
}
CallerObject.toggleCheckBoxListVisibility();
}
}(this);
this.documentClickHandler=function(CallerObject)
{
return function(mevent)
{
src=is.ie?window.event.srcElement:mevent.srcElement;
if(!src)src=is.ie?window.event.target:mevent.target;
var isClickInsideMainDiv=isElementInside(src,CallerObject.mainDiv)
if(isClickInsideMainDiv)
{
var isClickInsideCombo=isElementInside(src,CallerObject.comboBoxDiv);
if(isClickInsideCombo){
CallerObject.toggleCheckBoxListVisibility();
}
else{
}
}
else{
CallerObject.hideCheckBoxList();
}
}
}(this);
this.keyPressedHandler=function(CallerObject)
{
return function(e){
if(e==null)e=window.event;
var code=e.keyCode?e.keyCode:e.which;
if(code==9){
CallerObject.hideCheckBoxList();
return true;
}
else if(code==38){
CallerObject.hideCheckBoxList();
return false;
}
else if(code==40){
CallerObject.showCheckBoxList();
return false;
}
return true;
}
}(this);
this.comboBoxDiv.onmouseover=this.mouseOverHandler;
this.comboBoxDiv.onmouseout=this.mouseOutHandler;
this.comboBoxDiv.onmousedown=this.mouseDownHandler;
this.comboBoxDiv.onkeydown=this.keyPressedHandler;
if(is.ie){
document.body.attachEvent("onclick",this.documentClickHandler);
}
else{
window.addEventListener("click",this.documentClickHandler,false);
}
if(this.isCheckBoxListVisible()){
this.toggleCheckBoxListVisibility();
}
}
tfCBList.prototype.handleLegalSelection=function(item,newText){
this.comboTextDiv.innerHTML=newText;
if(item.folder!=null)
this.updateFolderFace(item.folder);
}
tfCBList.prototype.updateAllFoldersFace=function(){
for(var i=0;i<this.checkBoxList.folders.length;i++){
var folder=this.checkBoxList.folders[i];
this.updateFolderFace(folder);
}
}
tfCBList.prototype.updateFolderFace=function(folder){
var parentFolderDivs=this.getFolderDivs(folder);
for(var i=0;i<parentFolderDivs.length;i++){
var parentFolderDiv=parentFolderDivs[i];
var selectedItemsCount=this.getSelectedItemsCount(folder);
if(selectedItemsCount==0){
parentFolderDiv.className="folder";
}
else{
parentFolderDiv.className="folderSelected";
}
}
}
tfCBList.prototype.getFolderDivs=function(folder){
var result=[];
result.push(xGetElementById(folder.id+"-close"));
result.push(xGetElementById(folder.id+"-open"));
return result;
}
tfCBList.prototype.getSelectedItemsCount=function(folder){
var result=0;
for(var i=0;i<folder.items.length;i++){
var currentItem=folder.items[i];
if(currentItem.checkBox.checked){
result++;
}
}
return result;
}
tfCBList.prototype.getItemOuterDiv=function(item){
return xGetElementById(item.id).parentNode;
}
tfCBList.prototype.handleSelectionOverflow=function(item,warningText){
if(this.maxSelectionSize==1)
{
for(var i=0;i<this.checkBoxList.items.length;i++){
var itemP=this.checkBoxList.items[i];
itemP.select(false);
itemP.checkBox.checked=false;
}
item.select(true);
item.checkBox.checked=true;
}
else
{
item.checkBox.checked=false;
if(this.clickedCheckBoxes.length==0){
var outerDivElem=this.getItemOuterDiv(item);
var clickedLabelElement=getItemLabel(outerDivElem);
var clickedItem=item;
var clickedCheckBox=new ClickedCheckBox(clickedLabelElement,clickedItem);
this.clickedCheckBoxes.push(clickedCheckBox);
clickedCheckBox.labelElement.style.color=ERROR_DISPLAY_COLOR;
clickedCheckBox.labelElement.style.fontWeight=ERROR_DISPLAY_FONT_WEIGHT;
clickedCheckBox.labelElement.innerHTML=warningText;
}
}
}
function clearError(ddcblName){
var ddcbl=eval(ddcblName);
if(ddcbl.clickedCheckBoxes.length>0){
var clickedCheckBox=ddcbl.clickedCheckBoxes.pop();
clickedCheckBox.labelElement.style.color="";
clickedCheckBox.labelElement.style.fontWeight="";
clickedCheckBox.labelElement.innerHTML=clickedCheckBox.item.name;
}
}
tfCBList.prototype.isCheckBoxListVisible=function(){
return this.checkBoxListDiv.style.visibility=="hidden"?false:true;
}
tfCBList.prototype.toggleCheckBoxListVisibility=function(){
if(this.isCheckBoxListVisible())
{
this.hideCheckBoxList();
}else{
this.showCheckBoxList();
}
}
tfCBList.prototype.showCheckBoxList=function(){
var iFrameHack=xGetElementById(this.iFrameHackID);
if(iFrameHack!=null){
iFrameHack.style.display="block";
}
this.checkBoxListDiv.style.visibility="visible";
this.checkBoxListDiv.style.display="block";
}
tfCBList.prototype.hideCheckBoxList=function(){
var iFrameHack=xGetElementById(this.iFrameHackID);
if(iFrameHack!=null){
iFrameHack.style.display="none";
}
this.checkBoxListDiv.style.display="none";
this.checkBoxListDiv.style.visibility="hidden";
}
tfCBList.prototype.unselectAll=function(){
for(var i=0;i<this.checkBoxList.items.length;i++){
var item=this.checkBoxList.items[i];
item.select(false);
}
for(var i=0;i<this.checkBoxList.folders.length;i++){
var folder=this.checkBoxList.folders[i];
for(var j=0;j<folder.items.length;j++){
var item=folder.items[j];
item.select(false);
}
}
}
tfCBList.prototype.close=function(){
this.hideCheckBoxList();
}
function updateSelection(item,ddcbl){
if(item!=null){
var selectionSize=ddcbl.checkBoxList.getSelection().itemCount;
var maxSelectionSize=ddcbl.maxSelectionSize;
var newSelectionText=ddcbl.selectionTextFormatter(ddcbl);
if(selectionSize<=maxSelectionSize){
ddcbl.handleLegalSelection(item,newSelectionText);
}
else{
ddcbl.handleSelectionOverflow(item,newSelectionText);
window.setTimeout("clearError"+"('"+ddcbl.name+"')",ERROR_DISPLAY_TIMEOUT);
}
}
}
